package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.UserDAO;
import com.qf.entity.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author TZL
 * @date 2020/7/18
 */
@Service
@Transactional//自动管理事务
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDAO userDAO;

    @Override
    public int insertUser(User user) {
        return userDAO.insertUser(user);
    }

    @Override
    public int deleteUser(int id) {
        return userDAO.deleteUser(id);
    }

    @Override
    public int updateUser(User user) {
        return userDAO.updateUser(user);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public PageInfo<User> queryUserAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> users = userDAO.queryUserAll();
        return new PageInfo<User>(users);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public User selectUserById(int id) {
        return userDAO.selectUserById(id);
    }
}
